package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.scene.ScenePlayerInfo;
import com.yanqu.road.entity.scene.UserScene;
import com.yanqu.road.pb.scene.SceneProto;

public class ScenePb {

    public static UserScene parseUserScene(SceneProto.SceneMsg sceneMsg) {
        ScenePlayerInfo playerInfo = parseScenePlayerInfo(sceneMsg.getPlayerSceneInfo());
        return new UserScene(
                sceneMsg.getActivityId(),
                sceneMsg.getSceneType(),
                sceneMsg.getSceneId(),
                sceneMsg.getUserId(),
                playerInfo,
                sceneMsg.getUpdateTime()
        );
    }

    public static SceneProto.SceneMsg.Builder parseSceneMsg(UserScene userScene) {
        SceneProto.SceneMsg.Builder builder = SceneProto.SceneMsg.newBuilder();
        builder.setActivityId(userScene.getActivityId());
        builder.setSceneType(userScene.getSceneType());
        builder.setSceneId(userScene.getSceneId());
        builder.setUserId(userScene.getUserId());
        builder.setPlayerSceneInfo(parsePlayerSceneMsg(userScene.getPlayerSceneInfo()));
        builder.setUpdateTime(userScene.getUpdateTime());
        return builder;
    }

    public static SceneProto.SceneMsg.Builder parseSceneMsg(int activityId, int sceneType, String sceneId, ScenePlayerInfo playerSceneInfo, long updateTime) {
        SceneProto.SceneMsg.Builder builder = SceneProto.SceneMsg.newBuilder();
        builder.setActivityId(activityId);
        builder.setSceneType(sceneType);
        builder.setSceneId(sceneId);
        builder.setUserId(playerSceneInfo.getUserId());
        builder.setPlayerSceneInfo(parsePlayerSceneMsg(playerSceneInfo));
        builder.setUpdateTime(updateTime);
        return builder;
    }

    public static SceneProto.PlayerSceneMsg.Builder parsePlayerSceneMsg(long serverId, long userId, String nickName, String decoration) {
        SceneProto.PlayerSceneMsg.Builder builder = SceneProto.PlayerSceneMsg.newBuilder();
        builder.setServerId(serverId);
        builder.setUserId(userId);
        builder.setNickname(nickName);
        builder.setDecoration(decoration);
        return builder;
    }

    public static SceneProto.PlayerSceneMsg.Builder parsePlayerSceneMsg(ScenePlayerInfo scenePlayerInfo) {
        SceneProto.PlayerSceneMsg.Builder builder = SceneProto.PlayerSceneMsg.newBuilder();
        builder.setServerId(scenePlayerInfo.getServerId());
        builder.setUserId(scenePlayerInfo.getUserId());
        builder.setNickname(scenePlayerInfo.getNickName());
        builder.setDecoration(scenePlayerInfo.getDecoration());
        return builder;
    }

    public static ScenePlayerInfo parseScenePlayerInfo(SceneProto.PlayerSceneMsg playerMsg) {
        return new ScenePlayerInfo(
                playerMsg.getServerId(),
                playerMsg.getUserId(),
                playerMsg.getNickname(),
                playerMsg.getDecoration()
        );
    }

}
